package com.ppsea.work;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

import com.pat.java.base.Test;
import com.ppsea.Utils;
public class Xmy_QueryPlayer {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		int zoneId = 2;				//当前分区
		boolean isLocal = false;	//是否本地连接
		String cmd = "m_UPAct";
		String pars = "1_0";
		
		//各族族长名单
		String inputPlayerIdList = "C:\\Users\\smaller\\Desktop\\zone"+zoneId+"_list.txt";
		String outputPlayerIdList = "C:\\Users\\smaller\\Desktop\\zone"+zoneId+"_list_tmp.txt";
		
		
		List<String> playerList = new ArrayList<String>();
		BufferedReader input = null;
		DataOutputStream out = null;
		try {
			input = new BufferedReader(new InputStreamReader(new FileInputStream(inputPlayerIdList)));
//			out = new DataOutputStream(new FileOutputStream(outputPlayerIdList));
			
			
			String playerContent = input.readLine();
			while(playerContent != null){
				playerList.add(playerContent);
				playerContent = input.readLine();
			}
			input.close();
			
			for(String playerId : playerList){
				
				String domain = Utils.XMY_URL;// old domain fxwr.3g.qq.com
				if(zoneId == 0){
					domain = domain + "/0/admin/0/";
				}else if (zoneId == 1) {
					domain = domain + "/1/admin/1/";
				} else if (zoneId == 2) {
					domain = domain + "/2/admin/2/";
				}
				if(isLocal){
					domain = "http://localhost:1610"+zoneId+"/"+zoneId+"/";
				}
				if(!cmd.isEmpty()){
					domain = domain + cmd + "|" + playerId + "|";
				}
				if(!pars.isEmpty()){
					domain = domain + pars;
				}
				System.out.println("domain==>"+domain);
				
				//让玩家上线
				String returnStr = Test.testHttpUrlConnection(domain);
//				System.out.println("returnStr==>"+returnStr);
//				
//				JSONObject json;
//				try {
//					json = new JSONObject(returnStr);
//					int banAccountTime = (Integer) json.getJSONObject("player").get("banAccountTime");
//					if(banAccountTime > 0){
//						out.write(playerId.getBytes());
//						out.write("\r\n".getBytes());
//						
//						out.flush();
//					}
//				} catch (JSONException e) {
//					e.printStackTrace();
//				}
				
				
			}
//			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}